/**
 * @author 鍚存倍
 * @since 2022/10/13
 * 14:21
 */
package com.windgo.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.windgo.bean.MarketFeedback;
import com.windgo.bean.MarketFeedbackExample;
import com.windgo.bean.common.BasePageInfo;
import com.windgo.bean.common.CommonData;
import com.windgo.mapper.MarketFeedbackMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FeedbackServiceImpl implements  FeedbackService{
    @Autowired
    MarketFeedbackMapper marketFeedbackMapper;
    @Override
    public CommonData<MarketFeedback> list(BasePageInfo basePageInfo, Integer id) {
        PageHelper.startPage(basePageInfo.getPage(), basePageInfo.getLimit());
        MarketFeedbackExample marketFeedbackExample = new MarketFeedbackExample();
        marketFeedbackExample.setOrderByClause(basePageInfo.getSort()+" "+basePageInfo.getOrder());
        MarketFeedbackExample.Criteria criteria = marketFeedbackExample.createCriteria();
        if(id!=null){
            criteria.andIdEqualTo(id);
        }
        List<MarketFeedback> list = marketFeedbackMapper.selectByExample(marketFeedbackExample);
        PageInfo<MarketFeedback> marketFeedbackPageInfo = new PageInfo<>(list);
        return CommonData.data(marketFeedbackPageInfo);
    }

    @Override
    public CommonData<MarketFeedback> search(BasePageInfo basePageInfo, Integer id, String username) {
        PageHelper.startPage(basePageInfo.getPage(), basePageInfo.getLimit());
        MarketFeedbackExample marketFeedbackExample = new MarketFeedbackExample();
        marketFeedbackExample.setOrderByClause(basePageInfo.getSort()+" "+basePageInfo.getOrder());
        MarketFeedbackExample.Criteria criteria = marketFeedbackExample.createCriteria();
        if(id!=null){
            criteria.andIdEqualTo(id);
        }
        if(username!=null&&!"".equals(username)){
            criteria.andUsernameLike(username);
        }
        List<MarketFeedback> list = marketFeedbackMapper.selectByExample(marketFeedbackExample);
        PageInfo<MarketFeedback> marketFeedbackPageInfo = new PageInfo<>(list);
        return CommonData.data(marketFeedbackPageInfo);
    }
}

